var gotoOptions = false;

function openOptions() {
    var port = chrome.extension.connect();
    port.postMessage({ message: "openoptions" });
    gotoOptions = true;
    window.close();
}

function refreshBookmarks() {
    if (!gotoOptions) {
	var port = chrome.extension.connect();
	port.postMessage({ message: "refreshbookmarks" });
    }
}

function refreshBookmarksAndClose() {
    refreshBookmarks();
    window.close();
}

tables = document.getElementsByTagName("table");

myTable = tables[1];

myRow = myTable.insertRow(1);
myCell = myRow.insertCell(0);
myCell = myRow.insertCell(1);
myCell.align = "right";
myCell.innerHTML = "<font size='-1'><b>GBX+</b></font>"
myCell = myRow.insertCell(2);
myCell.innerHTML = "<font size='-1'>&nbsp;|&nbsp;</font>";
myCell = myRow.insertCell(3);
myCell.innerHTML = "<font size='-1'><a id ='refreshlink' href='javascript:window.close()'>Refresh now!</a></font>";
document.getElementById("refreshlink").onclick = refreshBookmarks;
myCell = myRow.insertCell(4);
myCell.innerHTML = "<font size='-1'>&nbsp;|&nbsp;</font>";
myCell = myRow.insertCell(5);
myCell.innerHTML = "<font size='-1'><a id='optionslink' href='javascript:window.close()'>Options</a></font>";
document.getElementById("optionslink").onclick = openOptions;
myCell = myRow.insertCell(6);
myCell.innerHTML = "<font size='-1'>&nbsp;|&nbsp;</font>";
myCell = myRow.insertCell(7);
myCell.innerHTML = "<font size='-1'><a href='http://gbx-plus.googlecode.com/' onclick='window.close()'>GBX+ Home</a>";

window.onunload = refreshBookmarksAndClose;